import { ExtractPropTypes } from 'vue'
import { KeyboardLangMode, KeyboardLangModes, KeyboardMode, KeyboardModes } from './type'
import { ZIndex } from '../../config'
import { UPDATE_MODEL_EVENT, UPDATE_SHOW_EVENT } from '../../constants'
/**
 * props参数
 */
export const keyboardProps = {
  /** 键盘输入的值 */
  modelValue: {
    type: [String, Number],
    default: ''
  },
  /** 控制键盘的显示/隐藏 */
  show: {
    type: Boolean,
    default: false
  },
  /** 键盘模式 */
  mode: {
    type: String,
    default: (): KeyboardMode => {
      return 'number'
    },
    validator: (value: KeyboardMode) => {
      return KeyboardModes.includes(value)
    }
  },
  /** 显示., 在mode为number时有效 */
  dot: {
    type: Boolean,
    default: true
  },
  /** 切换中/英状态, 在mode为car时有效 */
  langMode: {
    type: String,
    default: (): KeyboardLangMode => {
      return 'en'
    },
    validator: (value: KeyboardLangMode) => {
      return KeyboardLangModes.includes(value)
    }
  },
  /** 打乱顺序 */
  random: {
    type: Boolean,
    default: false
  },
  /** 显示遮罩 */
  mask: {
    type: Boolean,
    default: true
  },
  /** 透明遮罩 */
  transparentMask: {
    type: Boolean,
    default: true
  },
  /** ZIndex */
  zIndex: {
    type: [String, Number],
    default: ZIndex.popup
  }
}
export type KeyboardProps = ExtractPropTypes<typeof keyboardProps>

export const keyboardEmits = {
  [UPDATE_MODEL_EVENT]: (value: string | number) => typeof value === 'string' || typeof value === 'number',
  [UPDATE_SHOW_EVENT]: (value: boolean) => typeof value === 'boolean',
  'change': (value: string | number) => typeof value === 'string' || typeof value === 'number',
  cancel: () => true,
  confirm: (value: string | number) => typeof value === 'string' || typeof value === 'number'
}
export type KeyboardEmits = typeof keyboardEmits
